﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace NMigrate
{
	public abstract class FileHandler
	{
		public virtual bool CanExecute(FileInfo file)
		{
			if(!String.IsNullOrEmpty(Extension))
			{
				return file.Extension == ExtensionWithPoint;
			}
			throw new InvalidOperationException(this.GetType().Name + " should at least implements Extension property or CanExecute method");
		}


		public virtual string Extension
		{
			get
			{
				return null;
			}
		}

		string _ExtensionWithPoint;
		public string ExtensionWithPoint
		{
			get
			{
				if(_ExtensionWithPoint == null)
				{
					_ExtensionWithPoint = Extension;
					if(_ExtensionWithPoint.StartsWith("."))
						return _ExtensionWithPoint;
					_ExtensionWithPoint = "." + _ExtensionWithPoint;
				}
				return _ExtensionWithPoint;
			}
		}


		public abstract void Execute(FileInfo file, Configuration args);
		public abstract bool IsTemplated(FileInfo file);

		
	}
}
